home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / ProjectDrag 1.1b4 / Sources / ProjectDrag Sources / CheckIn.c next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  5.0 KB  |  190 lines  |  [TEXT/MPS ]

  1. /* CheckIn.c: CheckIn applet for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "Comments.h"
  20. #include "TasksAndErrors.h"
  21.  
  22.  
  23. void CheckInFile(FSSpec *file, Boolean doingFolder);
  24.  
  25.  
  26. /* This routine is called for each file passed in the ODOC event. */
  27.  
  28. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  29. {
  30. #pragma unused ( opening )
  31. #pragma unused ( userDataHandle )
  32.  
  33.     ProcessFileOrFolder(myFSSPtr, CheckInFile, ProcessFolder);
  34.     PopAllTasks();
  35. }
  36.  
  37.  
  38. void CheckInFile(FSSpec *file, Boolean doingFolder)
  39. {
  40.     Str63 userName;
  41.     Str15 nickname;
  42.     Str255 comment;
  43.     AEDesc command;
  44.     Str255 projectName;
  45.     OSErr err;
  46.     CKIDHandle theCKID;
  47.         
  48.     /* find the user name and initials */
  49.     err = GetUserSettings(userName, nickname, false);
  50.     if (err != noErr)
  51.     {
  52.         gDone = true;
  53.         return;
  54.     }
  55.  
  56.     /* get the CKID */
  57.     TaskStart(2001, 2, file->name, NULL, NULL, NULL); /* inspecting */
  58.     err = ExtractCKID(file, &theCKID);
  59.     TaskDone();
  60.     if (err != noErr)
  61.     {
  62.         /* add new file to project */
  63.         
  64.         /* confirm the add */
  65.         if (!ResTextYesNo(kProjectDragStrings, kConfirmAddFile, file->name, NULL, NULL, NULL))
  66.         {
  67.             RaiseErrorNumber(userCanceledErr);
  68.             return;
  69.         }
  70.         
  71.         TaskStart(2001, 3, file->name, NULL, NULL, NULL); /* adding */
  72.         
  73.         /* mount the project */
  74.         err = MountProjectFromFolder(file->vRefNum, file->parID, projectName);
  75.         if (err != noErr) return;
  76.  
  77.         /* get the checkin comment from the user */
  78.         comment[0] = 0;
  79.         if (!GetChangeComment(true, file->name, comment))
  80.             return;
  81.  
  82.         /* add the "first checked in" change comment and header */
  83.         err = AddFirstTimeHeader(file, userName, nickname, comment);
  84.         if (err != noErr) return;
  85.         
  86.         /* create a CheckIn command for SourceServer
  87.          * CheckIn -new -cs <comment> -project <project> -u <user> <file>
  88.          */
  89.         err = CreateCommand(&command, "CheckIn");
  90.         if (err == noErr)
  91.             err = AddCStringArg(&command, "-new");
  92.         if (err == noErr)
  93.             err = AddCommentArg(&command, comment);
  94.         if (err == noErr)
  95.             err = AddProjectArg(&command, projectName);
  96.         if (err == noErr)
  97.             err = AddUserArg(&command, userName);
  98.         if (err == noErr)
  99.             err = AddFileNameArg(&command, file);
  100.         if (err != noErr)
  101.         {
  102.             AEDisposeDesc(&command);
  103.             RaiseErrorNumber(err);
  104.             return;
  105.         }
  106.     }
  107.     else
  108.     {
  109.         /* Make sure the file is writeable.
  110.          * If the user dragged a folder, don't complain about all the errors!
  111.          * Just check in the ones that are OK to check in.
  112.          */
  113.         if (!(*theCKID)->writeable && !(*theCKID)->modifyReadOnly)
  114.         {
  115.             DisposeHandle((Handle)theCKID);
  116.             if (!doingFolder)
  117.                 RaiseErrorString(kProjectDragStrings, kNoCheckInPermission,
  118.                                  file->name, NULL, NULL, NULL);
  119.             return;
  120.         }
  121.         
  122.         TaskStart(2001, 1, file->name, NULL, NULL, NULL); /* checking in */
  123.  
  124.         /* XXX see if the version numbers match; if not, refuse to check in */
  125.         
  126.         /* XXX see if the modification date has changed; if not, put up an alert,
  127.          * and if the user confirms, bump the mod date to avoid an error
  128.          */
  129.     
  130.         /* extract the checkout comment from the CKID */
  131.         {
  132.             StringPtr s = (*theCKID)->projectPath; /* careful -- not locked down */
  133.             s += s[0] + 2;        /* skip the project name and null character */
  134.             s += s[0] + 2;        /* skip the user name and null character */
  135.             s += s[0] + 2;        /* skip the revision number and null character */
  136.             s += s[0] + 2;        /* skip the file name and null character */
  137.             if (s[0] == 0)        /* seems to put three chars in null string.... */
  138.                 s += 3;            /* skip the task and null character */
  139.             else
  140.                 s += s[0] + 2;    /* skip the task and null character */
  141.             BlockMove(s, comment, s[0] + 1); /* copy the comment */
  142.         }
  143.         
  144.         /* add the change comment to the file header */
  145.         err = AddCheckinComment(file, userName, nickname, comment);
  146.         if (err != noErr)
  147.         {
  148.             DisposeHandle((Handle)theCKID);
  149.             return;
  150.         }
  151.         
  152.         /* mount the project */
  153.         err = MountProjectFromCKID(theCKID, projectName);
  154.         DisposeHandle((Handle)theCKID);
  155.         if (err != noErr) return;
  156.         
  157.         /* create a CheckIn command for SourceServer
  158.          * CheckIn -cs <comment> -project <project> -u <user> <file>
  159.          */
  160.         err = CreateCommand(&command, "CheckIn");
  161.         if (err == noErr)
  162.             err = AddCommentArg(&command, comment);
  163.         if (err == noErr)
  164.             err = AddProjectArg(&command, projectName);
  165.         if (err == noErr)
  166.             err = AddUserArg(&command, userName);
  167.         if (err == noErr)
  168.             err = AddFileNameArg(&command, file);
  169.         if (err != noErr)
  170.         {
  171.             AEDisposeDesc(&command);
  172.             RaiseErrorNumber(err);
  173.             return;
  174.         }
  175.     }
  176.     
  177.     err = SendCommand(&command);        /* send the command to SourceServer */
  178.     if (err == noErr)
  179.         TaskDone();
  180. }
  181.  
  182.  
  183. void DoFileMenu(short itemID)
  184. {
  185.     if ( itemID == 1 )
  186.         SelectFile();        // call file selection userProc
  187.     else
  188.         SendQuitToSelf();    // send self a 'quit' event
  189. }
  190.